var ztype = "user";
function beforeDrag(treeId, treeNodes) {
	return true;
}
function beforeDrop(treeId, treeNodes, targetNode, moveType) {
	return targetNode ? targetNode.drop !== false : true;
}

function afterDrop(event, treeId, treeNodes, targetNode, moveType) {
	if(targetNode==null)return;
	var parent = targetNode.getParentNode();	
	var node = treeNodes[0];
	if (moveType == 'prev') {
		node.sort = targetNode.sort - 1;
	} else if (moveType == 'next') {
		node.sort = targetNode.sort + 1;
	}
	var childs = parent.chldren;
}

function zTreeOnExpand(event, treeId, treeNode) {
    var parent = targetNode.getParentNode();
	alert(parent.children.length);
}

$(document).ready(function() {
	var tsetting = {
		async : {
			enable : true,
			url : "business/component!ztreeall",
			autoParam : [ "id=bean.id" ],
			otherParam : {}
		// dataFilter: filter
		},
		edit : {
			enable : true,
			showRemoveBtn : false,
			showRenameBtn : false,
			drag:{
				isCopy:false,
				isMove:true,
				prev:true,
				inner:false,
				next:true				
				
			}
		},
		data : {
			simpleData : {
				enable : true
			}
		},
		callback : {
			onDrop : afterDrop,
			beforeDrop : beforeDrop,
			beforeDrag : beforeDrag,
			onExpand:zTreeOnExpand
		}
	};

	var tzNodes = [ {
		name : "北方特种能源有限公司西安庆华公司",
		open : true,
		nocheck : true,
		id : "root",
		isParent : true
	} ];
	$.fn.zTree.init($("#deptTree"), tsetting, tzNodes);
	var zTree = $.fn.zTree.getZTreeObj("deptTree");	
	$("#saveSort").bind("click", function() {
		alert(this);
	});
});
